from user import *
import zmail

subject = 'test'  # 邮件主题
content_text = 'test'  # 邮件内容
attachments = ['test.png']  # 邮件附件
mail_to = [user.mail_to for user in Users]  # 收件人列表


class ZMailObject(object):
    def __init__(self, _account, _authorization_code):
        # 邮箱账号
        self.account = _account
        # 邮箱授权码
        self.authorization_code = _authorization_code
        # 构建一个邮箱服务对象
        self.server = zmail.server(self.account, self.authorization_code)

    def send_mail(self, _mail_to, _subject, _content_text, _attachments=None):
        # `邮件主体
        mail_body = {
            'subject': _subject,
            'content_text': _content_text,  # 纯文本或者HTML内容
            'attachments': _attachments,
        }
        self.server.send_mail(_mail_to, mail_body)


mail = ZMailObject(account, authorization_code)
# mail.send_mail(host, subject, content_text)
